package face.pay.web.withdraw.controller;

import face.pay.entity.UserInfo;
import face.pay.entity.UserBankInfo;
import face.pay.security.annotation.CurrentUser;
import face.pay.util.ResultMessage;
import face.pay.web.withdraw.service.IUserBankInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/withdrawUser")
@Slf4j
public class UserBankInfoController {

    @Autowired
    private IUserBankInfoService iUserBankInfoService;

    /**
     * 用户提现配置
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/info")
    public String userConfig(@CurrentUser UserInfo loginUser, Model model) {

        UserBankInfo userBankInfo = iUserBankInfoService.queryUserBankInfo(loginUser);

        model.addAttribute("userBankConfig", userBankInfo);
        return "withdraw/userBankConfig";
    }


    /**
     * 更新用户银行卡信息
     *
     * @param
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public ResultMessage editUserConfig(UserBankInfo userConfig, @CurrentUser UserInfo loginUser, String validateCode) {
        return iUserBankInfoService.updateUserBankInfo(userConfig, loginUser,validateCode);
    }
}
